package com.hemi.rhet.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import android.app.Activity;
import android.content.Context;

public class AppParam {
	private static AppParam app =null;
	private Context act = null;
	public static AppParam newInstance(Context act){
		if(app==null)
		{
			app=  new AppParam(act);
		}
		app.act=act;
		return app;
	}
	Properties pro = null;
	
	private AppParam(Context act){
		try {
			this.act = act;
			  pro = new Properties();
//			pro.load(act.getResources().getAssets().open("app.properties"));
			  pro.load(act.openFileInput("app.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
	public String get(String key){
		return  pro.getProperty(key);
	}
	
	public void put(String key,String value)
	{
		pro.setProperty(key, value);
	}
	public void save() {  
		System.out.println("save.....................呗调用....");
		 try {  
//			 	FileOutputStream s = new FileOutputStream("/android_asset/app.properties");  
			 	
			 	  FileOutputStream s = act.openFileOutput("app.properties",Context. MODE_APPEND  );
			 	pro.store(s, "");  
			} catch (Exception e){  
			e.printStackTrace();  
		}  
	} 
	
	public static String getParam(Context act,String key)
	{
		if(app==null)
		{
			AppParam aa = newInstance(act);
			return aa.get(key);
		}
		return app.get(key);
	}
	
}
